package com.zhiyou.controller;

import com.zhiyou.entity.Column;
import com.zhiyou.util.ColumnUtil;
import com.zhiyou.util.DBUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @author sanshi
 * @desc
 * @create 2021-09-14 15:17
 */
@WebServlet("/ColumnDelete")
public class ColumnDelete extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String deleteColumnId = req.getParameter("deleteColumnId2");
        Object[] params = {deleteColumnId};
        String sql = "delete from news_chnl where id = ?";
        int i = new DBUtil().updateInfo(sql, params);
        if (i==0){
            resp.sendRedirect("columnError.jsp");
        }else{
            HttpSession session = req.getSession();
            List<Column> columnList = new ColumnUtil().getAllColumn();
            session.setAttribute("columnList",columnList);
            session.setAttribute("deleteColumn","success");
            resp.sendRedirect("/page/ColumnManagement.jsp");
        }
    }
}
